package com.jingdianjichi.project.domain.handler.subject;

import com.jingdianjichi.project.common.enums.IsDeletedFlagEnum;
import com.jingdianjichi.project.common.enums.SubjectInfoTypeEnum;
import com.jingdianjichi.project.domain.bo.SubjectInfoBo;
import com.jingdianjichi.project.domain.bo.SubjectOptionBo;
import com.jingdianjichi.project.domain.convert.BriefSubjectConverter;
import com.jingdianjichi.project.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.project.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * ClassName:RadioTypeHandler
 * Package:com.jingdianjichi.subject.domain.handler.subject
 * Description:
 *
 * @Author fst
 * @Create 2024/9/29 13:29
 * @Version 1.0
 */


/**
 * 简答题目
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler
{
    @Resource
    private SubjectBriefService subjectBriefService;



    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBo)
    {
        //简答题目的插入
        SubjectBrief subjectBrief = BriefSubjectConverter.INSTANCE.convertBoToEntity(subjectInfoBo);
        subjectBrief.setSubjectId(subjectInfoBo.getId().intValue());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBo query(int subjectId) {
        SubjectBrief subjectBrief=subjectBriefService.queryById(Long.valueOf(subjectId));
        SubjectOptionBo subjectOptionBo=new SubjectOptionBo();
        subjectOptionBo.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectOptionBo;
    }

}
